<?php
namespace Doc\Controller;
use Think\Controller;

class MakeController extends Controller {

	function index($id) {
		if (IS_POST) {
			$data = I('post.data');
			parse_str($data, $array);
			$list = array();
			foreach ($array as $key => $value) {
				if (empty($value)) {
					unset($array[$key]);
				}
			}
			$key = M('Category')->where('id='.$id)->getField('key');
			$Aes = new \Common\ORG\Aes($key);
			$res = $Aes->siyuan_aes_encode(json_encode($array));
			$this->ajaxReturn($res);
		} else {
			$this->display();
		}
	}

	function decode($id) {
		if (IS_POST) {
			$data = I('post.data');
			$key = M('Category')->where('id='.$id)->getField('key');
			$Aes = new \Common\ORG\Aes($key);
			$data = str_replace(" ", "+", $data);
			$this->ajaxReturn(urldecode($Aes->siyuan_aes_decode($data)));
		} else {
			$this->display();
		}
	}
}